package com.sumainfor.pc.gmio.controller.MktFeign;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ListMapMergeUtil;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.feign.BaseFeignZuul;
import com.sumainfor.pc.gmio.service.impl.HousingOwadvanceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 * 业主提前收房
 *
 * @Auther: zhlu
 * @Date: 2019/1/12 15:52
 * @Description:
 */
@RestController
@RequestMapping("/key/houow")
public class HousingOwadvanceController {

    Logger log = LoggerFactory.getLogger(HousingOwadvanceController.class);

    @Autowired
    HousingOwadvanceService housingOwadvanceService;

    @Autowired
    BaseFeignZuul BaseFeignZuul;

    /**
     * 功能描述:
     * 获取业主提前收房列表
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/1/12 15:57
     */
    @GetMapping("/getHousingOwList")
    public JsonResult getHousingOwList(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        log.info("运营部");
        params.put("delfg", 0);
//        params.put("Status",1);
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer count = housingOwadvanceService.getHousingOwListCout(params);
        if (count == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, count);
        }
        List<Map<String, Object>> getHousingOwList = housingOwadvanceService.getHousingOwList(params);
        List<Map<String, Object>> getDeptList = BaseFeignZuul.getDeptList(params);
//        getHousingOwList= ListMapMergeUtil.ListTranStringUtils(getHousingOwList,getDeptList,"MiId","DeptId","DeptName","MiName");
        for (Map<String, Object> map : getHousingOwList) {
            if (FieldCheckUtil.isMapFieldNotNull(map, new String[]{"MiId"})) {
                map = ListMapMergeUtil.MapTranStringUtils(map, getDeptList, "MiId", "DeptId", "DeptName", "MiName");
            }
        }
        result = pageUtils.getJsonResult(getHousingOwList, params, count);
        return result;
    }

    /**
     * 功能描述:
     * 业主放弃提前收房
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/1/15 19:52
     */
    @ResponseBody
    @PostMapping("/UpdateHousingOwGiveUp")
    public JsonResult UpdateHousingOwGiveUp(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        if (housingOwadvanceService.UpdateHousingOwGiveUp(params)) {
            result.putSuccess("取消提前收房！");
        } else {
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述:
     * 发起违约单
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/1/16 15:28
     */
    @ResponseBody
    @PostMapping("/AddHousingOwInfo")
    public JsonResult AddHousingOwInfo(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        if (housingOwadvanceService.AddHousingOwInfo(params)) {
            result.putSuccess("违约单填写成功！");
        } else {
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }


    /**
     * 查询收费标准数据 根据收费标准的编号进行查询
     *
     * @param chaId
     * @return
     */
    @ResponseBody
    @PostMapping("/getChargesData")
    public JsonResult getChargesData(String chaId) {
        return housingOwadvanceService.getChargesData(chaId);
    }
}
